// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Electric Orb Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 50 : TYPE_ELECTRICORB

// Function declarations
reserve function ElectricOrb_DebugDraw
reserve function ElectricOrb_DebugSpawn

// Static Values
public value ElectricOrb_value33 = 0;

// Tables

function ElectricOrb_DebugDraw
	temp0 = object.direction
	object.direction = object.value17
	object.direction -= ElectricOrb_value33
	object.direction--
	object.direction <<= FLIP_X
	DrawSpriteFX(0, FX_FLIP, object.xpos, object.ypos)
	object.direction = temp0
end function


function ElectricOrb_DebugSpawn
	temp0 = object.value17
	temp0 -= ElectricOrb_value33
	temp0--
	temp0 <<= 1
	CreateTempObject(TypeName[Electric Orb], 0, object.xpos, object.ypos)
	object[tempObjectPos].direction = temp0
	object[tempObjectPos].drawOrder = 4
end function


event ObjectMain
	switch object.value1
	default
		temp0 = SBZSetup_value29
		break
	case 2
		temp0 = SBZSetup_value29
		temp0 %= 12
		break
	case 4
		temp0 = SBZSetup_value29
		temp0 %= 6
		break
	end switch
	switch temp0
	case 0
		if SBZSetup_value30 == 1
			temp0 = object.ixpos
			temp0 -= screen.cameraX
			Abs(temp0)
			if temp0 < screen.xcenter
				temp0 = object.iypos
				temp0 -= screen.cameraY
				Abs(temp0)
				if temp0 < screen.ycenter
					PlaySfx(SfxName[Electric Arc], 0)
				end if
			end if
		end if
		break
	case 1
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -8, -8, 8, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				CallFunction(PlayerObject_LightningHit)
			end if
		next
		break
	case 2
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -36, -8, 36, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				CallFunction(PlayerObject_LightningHit)
			end if
		next
		break
	case 3
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -36, -8, 36, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				CallFunction(PlayerObject_LightningHit)
			end if
		next
		break
	case 4
	case 5
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -64, -8, 64, 8, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				CallFunction(PlayerObject_LightningHit)
			end if
		next
		break
	end switch
end event


event ObjectDraw
	switch object.value1
	default
		DrawSpriteFX(SBZSetup_value29, FX_FLIP, object.xpos, object.ypos)
		break
	case 2
		temp0 = SBZSetup_value29
		temp0 %= 12
		DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
		break
	case 4
		temp0 = SBZSetup_value29
		temp0 %= 6
		DrawSpriteFX(temp0, FX_FLIP, object.xpos, object.ypos)
		break
	end switch
end event


event ObjectStartup
	LoadSpriteSheet("SBZ/Objects.gif")
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 75, 479)
	SpriteFrame(-36, -10, 76, 34, 92, 477)
	SpriteFrame(-36, -10, 76, 34, 169, 477)
	SpriteFrame(-64, -10, 132, 34, 246, 477)
	SpriteFrame(-64, -10, 132, 34, 379, 477)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	SpriteFrame(-8, -8, 16, 32, 58, 479)
	foreach (TypeName[Electric Orb], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].propertyValue
		object[arrayPos0].value1 >>= 1
		object[arrayPos0].value1 &= 3
		object[arrayPos0].value1 <<= 1
		object[arrayPos0].propertyValue &= 1
		if object[arrayPos0].propertyValue == 1
			object[arrayPos0].direction = FLIP_Y
		else
			object[arrayPos0].direction = FLIP_NONE
		end if
		object[arrayPos0].drawOrder = 4
	next
	temp0 = 0
	ElectricOrb_value33 = DebugMode_ObjCount
	ElectricOrb_value33--
	while temp0 < 2
		SetTableValue(TypeName[Electric Orb], DebugMode_ObjCount, DebugMode_TypesTable)
		SetTableValue(ElectricOrb_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
		SetTableValue(ElectricOrb_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
		DebugMode_ObjCount++
		temp0++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
